package banksimulator.ui;

import banksimulator.bank.Transaction;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * <p>这是一个DefaultTableCellRenderer的实现，它用来设置表格单元格的渲染方式。
 * <p>此渲染器用于控制显示帐户交易记录的表格的呈现方式：帐户存款的行会显示蓝色，取款的交易会显示为红色。
 * @author Rajab
 */
public class TransactionTableRender extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        String trans = (String) table.getValueAt(row, 1);
        if (trans.equals(Transaction.Type.DEPOSIT.toString())) {
            setForeground(Color.BLUE);
        } else if (trans.equals(Transaction.Type.WITHDRAW.toString())) {
            setForeground(Color.RED);
        }else {
            setForeground(Color.BLACK);
        }

        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}
